# -*- coding: utf-8 -*-
# 坐标转换
import json
import urllib
import math
x_pi = 3.14159265358979324 * 3000.0 / 180.0
pi = 3.1415926535897932384626  # π
a = 6378245.0  # 长半轴
ee = 0.00669342162296594323  # 偏心率平方


def wgs84_gd(lon, lat):
    '''
        高德服务接口
    '''
    URL = "http://restapi.amap.com/v3/assistant/coordinate/convert?key=be1d618da198ae417217c825076f5f14&locations=%s,%s&coordsys=gps" % (
        lon, lat)
    print(URL)
    response = urllib.urlopen(URL)
    data = json.loads(response.read())['locations'].split(',')
    return [float(data[0]), float(data[1])]


def wgs84_baidu(lon, lat):
    '''
        百度服务接口
    '''
    URL = "http://api.map.baidu.com/geoconv/v1/?coords=%s,%s&from=1&to=5&ak=sGSOaO07WkRHHiCRxxbSQVBn  " % (
        lon, lat)
    # print URL
    response = urllib.urlopen(URL)
    data = json.loads(response.read())['result'][0]
    return [float(data['x']), float(data['y'])]
